/*     */ package com.zimbra.cs.filter;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.mailbox.DeliveryContext;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.Message;
/*     */ import com.zimbra.cs.mailbox.OperationContext;
/*     */ import com.zimbra.cs.mime.ParsedMessage;
/*     */ import com.zimbra.cs.service.util.ItemId;
/*     */ import com.zimbra.cs.service.util.SpamHandler;
/*     */ import com.zimbra.soap.mail.type.FilterRule;
/*     */ import java.io.BufferedReader;
/*     */ import java.io.ByteArrayInputStream;
/*     */ import java.io.IOException;
/*     */ import java.io.StringReader;
/*     */ import java.io.UnsupportedEncodingException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.regex.Matcher;
/*     */ import java.util.regex.Pattern;
/*     */ import org.apache.jsieve.ConfigurationManager;
/*     */ import org.apache.jsieve.SieveFactory;
/*     */ import org.apache.jsieve.exception.SieveException;
/*     */ import org.apache.jsieve.parser.generated.Node;
/*     */ import org.apache.jsieve.parser.generated.ParseException;
/*     */ import org.apache.jsieve.parser.generated.TokenMgrError;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class RuleManager
/*     */ {
/*  62 */   private static final String FILTER_RULES_CACHE_KEY = RuleManager.class.getSimpleName() + ".FILTER_RULES_CACHE";
/*     */   
/*  64 */   private static final String OUTGOING_FILTER_RULES_CACHE_KEY = RuleManager.class.getSimpleName() + ".OUTGOING_FILTER_RULES_CACHE";
/*     */   
/*     */ 
/*  67 */   private static SieveFactory SIEVE_FACTORY = createSieveFactory();
/*     */   
/*     */ 
/*     */   private static SieveFactory createSieveFactory()
/*     */   {
/*     */     ConfigurationManager mgr;
/*     */     
/*     */     try
/*     */     {
/*  76 */       mgr = new ZimbraConfigurationManager();
/*     */     } catch (SieveException e) {
/*  78 */       ZimbraLog.filter.error("Unable to initialize mail filtering extensions.", e);
/*  79 */       return null;
/*     */     }
/*     */     
/*  82 */     Map<String, String> commandMap = mgr.getCommandMap();
/*  83 */     commandMap.putAll(JsieveConfigMapHandler.getCommandMap());
/*     */     
/*  85 */     Map<String, String> testMap = mgr.getTestMap();
/*  86 */     testMap.putAll(JsieveConfigMapHandler.getTestMap());
/*     */     
/*  88 */     return mgr.build();
/*     */   }
/*     */   
/*     */   public static SieveFactory getSieveFactory() {
/*  92 */     return SIEVE_FACTORY;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private static void setRules(Account account, String script, String sieveScriptAttrName, String rulesCacheKey)
/*     */     throws ServiceException
/*     */   {
/* 107 */     String accountId = account.getId();
/* 108 */     ZimbraLog.filter.debug("Setting filter rules for account %s:\n%s", new Object[] { accountId, script });
/* 109 */     if (script == null) {
/* 110 */       script = "";
/*     */     }
/*     */     try {
/* 113 */       Node node = parse(script);
/*     */       
/* 115 */       SIEVE_FACTORY.evaluate(new DummyMailAdapter(), node);
/*     */       
/* 117 */       Map<String, Object> attrs = new HashMap();
/* 118 */       attrs.put(sieveScriptAttrName, script);
/* 119 */       Provisioning.getInstance().modifyAttrs(account, attrs);
/* 120 */       account.setCachedData(rulesCacheKey, node);
/*     */     } catch (ParseException e) {
/* 122 */       ZimbraLog.filter.error("Unable to parse script:\n" + script);
/* 123 */       throw ServiceException.PARSE_ERROR("parsing Sieve script", e);
/*     */     } catch (TokenMgrError e) {
/* 125 */       ZimbraLog.filter.error("Unable to parse script:\n" + script);
/* 126 */       throw ServiceException.PARSE_ERROR("parsing Sieve script", e);
/*     */     } catch (SieveException e) {
/* 128 */       ZimbraLog.filter.error("Unable to evaluate script:\n" + script);
/* 129 */       throw ServiceException.PARSE_ERROR("evaluating Sieve script", e);
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static void clearCachedRules(Account account)
/*     */   {
/* 139 */     account.setCachedData(FILTER_RULES_CACHE_KEY, null);
/* 140 */     account.setCachedData(OUTGOING_FILTER_RULES_CACHE_KEY, null);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public static String getIncomingRules(Account account)
/*     */   {
/* 147 */     return getRules(account, "zimbraMailSieveScript");
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public static String getOutgoingRules(Account account)
/*     */   {
/* 154 */     return getRules(account, "zimbraMailOutgoingSieveScript");
/*     */   }
/*     */   
/*     */   private static String getRules(Account account, String sieveScriptAttrName) {
/* 158 */     return account.getAttr(sieveScriptAttrName);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private static Node getRulesNode(Account account, String sieveScriptAttrName, String rulesCacheKey)
/*     */     throws ParseException
/*     */   {
/* 171 */     Node node = (Node)account.getCachedData(rulesCacheKey);
/* 172 */     if (node == null) {
/* 173 */       String script = getRules(account, sieveScriptAttrName);
/* 174 */       if (script == null) {
/* 175 */         script = "";
/*     */       }
/* 177 */       node = parse(script);
/* 178 */       account.setCachedData(rulesCacheKey, node);
/*     */     }
/* 180 */     return node;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public static List<FilterRule> getIncomingRulesAsXML(Account account)
/*     */     throws ServiceException
/*     */   {
/* 189 */     return getRulesAsXML(account, "zimbraMailSieveScript", FILTER_RULES_CACHE_KEY);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public static List<FilterRule> getOutgoingRulesAsXML(Account account)
/*     */     throws ServiceException
/*     */   {
/* 198 */     return getRulesAsXML(account, "zimbraMailOutgoingSieveScript", OUTGOING_FILTER_RULES_CACHE_KEY);
/*     */   }
/*     */   
/*     */   private static List<FilterRule> getRulesAsXML(Account account, String sieveScriptAttrName, String rulesCacheKey) throws ServiceException
/*     */   {
/*     */     Node node;
/*     */     try {
/* 205 */       node = getRulesNode(account, sieveScriptAttrName, rulesCacheKey);
/*     */     } catch (ParseException e) {
/* 207 */       throw ServiceException.PARSE_ERROR("parsing Sieve script", e);
/*     */     } catch (TokenMgrError e) {
/* 209 */       throw ServiceException.PARSE_ERROR("parsing Sieve script", e);
/*     */     }
/* 211 */     SieveToSoap sieveToSoap = new SieveToSoap(getRuleNames(account.getAttr(sieveScriptAttrName)));
/* 212 */     sieveToSoap.accept(node);
/* 213 */     return sieveToSoap.toFilterRules();
/*     */   }
/*     */   
/* 216 */   private static final Pattern PAT_RULE_NAME = Pattern.compile("# (.+)");
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public static List<String> getRuleNames(String script)
/*     */   {
/* 223 */     List<String> names = new ArrayList();
/* 224 */     if (script != null) {
/* 225 */       BufferedReader reader = new BufferedReader(new StringReader(script));
/*     */       try {
/*     */         String line;
/* 228 */         while ((line = reader.readLine()) != null) {
/* 229 */           Matcher matcher = PAT_RULE_NAME.matcher(line);
/* 230 */           if (matcher.matches()) {
/* 231 */             names.add(matcher.group(1));
/*     */           }
/*     */         }
/*     */       } catch (IOException e) {
/* 235 */         ZimbraLog.filter.warn("Unable to determine filter rule names.", e);
/*     */       }
/*     */     }
/* 238 */     return names;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public static String getRuleByName(String script, String ruleName)
/*     */   {
/* 246 */     if (script == null) {
/* 247 */       return null;
/*     */     }
/*     */     
/* 250 */     StringBuilder buf = new StringBuilder();
/* 251 */     boolean found = false;
/* 252 */     BufferedReader reader = new BufferedReader(new StringReader(script));
/*     */     try
/*     */     {
/*     */       String line;
/* 256 */       while ((line = reader.readLine()) != null) {
/* 257 */         Matcher matcher = PAT_RULE_NAME.matcher(line);
/* 258 */         if (matcher.matches()) {
/* 259 */           String currentName = matcher.group(1);
/* 260 */           if (currentName.equals(ruleName))
/*     */           {
/* 262 */             found = true; } else {
/* 263 */             if (found) {
/*     */               break;
/*     */             }
/*     */           }
/*     */         }
/* 268 */         if (found) {
/* 269 */           buf.append(line).append("\r\n");
/*     */         }
/*     */       }
/*     */     } catch (IOException e) {
/* 273 */       ZimbraLog.filter.warn("Unable to get rule %s from script:\n%s.", ruleName, script, e);
/*     */     }
/*     */     
/* 276 */     if (buf.length() > 0) {
/* 277 */       return buf.toString();
/*     */     }
/* 279 */     return null;
/*     */   }
/*     */   
/*     */   public static void setIncomingXMLRules(Account account, List<FilterRule> rules) throws ServiceException
/*     */   {
/* 284 */     setXMLRules(account, rules, "zimbraMailSieveScript", FILTER_RULES_CACHE_KEY);
/*     */   }
/*     */   
/*     */   public static void setOutgoingXMLRules(Account account, List<FilterRule> rules) throws ServiceException {
/* 288 */     setXMLRules(account, rules, "zimbraMailOutgoingSieveScript", OUTGOING_FILTER_RULES_CACHE_KEY);
/*     */   }
/*     */   
/*     */   private static void setXMLRules(Account account, List<FilterRule> rules, String sieveScriptAttrName, String rulesCacheKey) throws ServiceException
/*     */   {
/* 293 */     SoapToSieve soapToSieve = new SoapToSieve(rules);
/* 294 */     String script = soapToSieve.getSieveScript();
/* 295 */     setRules(account, script, sieveScriptAttrName, rulesCacheKey);
/*     */   }
/*     */   
/*     */ 
/*     */   public static List<ItemId> applyRulesToIncomingMessage(OperationContext octxt, Mailbox mailbox, ParsedMessage pm, int size, String recipient, DeliveryContext sharedDeliveryCtxt, int incomingFolderId, boolean noICal)
/*     */     throws ServiceException
/*     */   {
/* 302 */     return applyRulesToIncomingMessage(octxt, mailbox, pm, size, recipient, sharedDeliveryCtxt, incomingFolderId, noICal, true);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static List<ItemId> applyRulesToIncomingMessage(OperationContext octxt, Mailbox mailbox, ParsedMessage pm, int size, String recipient, DeliveryContext sharedDeliveryCtxt, int incomingFolderId, boolean noICal, boolean allowFilterToMountpoint)
/*     */     throws ServiceException
/*     */   {
/* 318 */     List<ItemId> addedMessageIds = null;
/* 319 */     IncomingMessageHandler handler = new IncomingMessageHandler(octxt, sharedDeliveryCtxt, mailbox, recipient, pm, size, incomingFolderId, noICal);
/*     */     
/* 321 */     ZimbraMailAdapter mailAdapter = new ZimbraMailAdapter(mailbox, handler);
/* 322 */     mailAdapter.setAllowFilterToMountpoint(allowFilterToMountpoint);
/*     */     try
/*     */     {
/* 325 */       Account account = mailbox.getAccount();
/* 326 */       Node node = getRulesNode(account, "zimbraMailSieveScript", FILTER_RULES_CACHE_KEY);
/*     */       
/*     */ 
/* 329 */       boolean applyRules = true;
/* 330 */       if (node == null) {
/* 331 */         applyRules = false;
/*     */       }
/* 333 */       if ((SpamHandler.isSpam(handler.getMimeMessage())) && (!account.getBooleanAttr("zimbraSpamApplyUserFilters", false)))
/*     */       {
/*     */ 
/* 336 */         applyRules = false;
/*     */       }
/*     */       
/* 339 */       if (applyRules) {
/* 340 */         SIEVE_FACTORY.evaluate(mailAdapter, node);
/*     */         
/* 342 */         addedMessageIds = mailAdapter.getAddedMessageIds();
/*     */       }
/*     */     } catch (Exception e) {
/* 345 */       ZimbraLog.filter.warn("An error occurred while processing filter rules. Filing message to %s.", handler.getDefaultFolderPath(), e);
/*     */ 
/*     */     }
/*     */     catch (TokenMgrError e)
/*     */     {
/* 350 */       ZimbraLog.filter.warn("An error occurred while processing filter rules. Filing message to %s.", handler.getDefaultFolderPath(), e);
/*     */     }
/*     */     
/* 353 */     if (addedMessageIds == null)
/*     */     {
/* 355 */       Message msg = mailAdapter.doDefaultFiling();
/* 356 */       addedMessageIds = new ArrayList(1);
/* 357 */       addedMessageIds.add(new ItemId(msg));
/*     */     }
/* 359 */     return addedMessageIds;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public static List<ItemId> applyRulesToOutgoingMessage(OperationContext octxt, Mailbox mailbox, ParsedMessage pm, int sentFolderId, boolean noICal, int flags, String[] tags, int convId)
/*     */     throws ServiceException
/*     */   {
/* 367 */     List<ItemId> addedMessageIds = null;
/* 368 */     OutgoingMessageHandler handler = new OutgoingMessageHandler(mailbox, pm, sentFolderId, noICal, flags, tags, convId, octxt);
/*     */     
/* 370 */     ZimbraMailAdapter mailAdapter = new ZimbraMailAdapter(mailbox, handler);
/*     */     try {
/* 372 */       Account account = mailbox.getAccount();
/* 373 */       Node node = getRulesNode(account, "zimbraMailOutgoingSieveScript", OUTGOING_FILTER_RULES_CACHE_KEY);
/* 374 */       if (node != null) {
/* 375 */         SIEVE_FACTORY.evaluate(mailAdapter, node);
/*     */         
/* 377 */         addedMessageIds = mailAdapter.getAddedMessageIds();
/*     */       }
/*     */     } catch (Exception e) {
/* 380 */       ZimbraLog.filter.warn("An error occurred while processing filter rules. Filing message to %s.", handler.getDefaultFolderPath(), e);
/*     */     }
/*     */     catch (TokenMgrError e) {
/* 383 */       ZimbraLog.filter.warn("An error occurred while processing filter rules. Filing message to %s.", handler.getDefaultFolderPath(), e);
/*     */     }
/*     */     
/* 386 */     if (addedMessageIds == null)
/*     */     {
/* 388 */       Message msg = mailAdapter.doDefaultFiling();
/* 389 */       addedMessageIds = new ArrayList(1);
/* 390 */       addedMessageIds.add(new ItemId(msg));
/*     */     }
/* 392 */     return addedMessageIds;
/*     */   }
/*     */   
/*     */   public static boolean applyRulesToExistingMessage(OperationContext octxt, Mailbox mbox, int messageId, Node node) throws ServiceException
/*     */   {
/* 397 */     Message msg = mbox.getMessageById(octxt, messageId);
/* 398 */     ExistingMessageHandler handler = new ExistingMessageHandler(octxt, mbox, messageId, (int)msg.getSize());
/* 399 */     ZimbraMailAdapter mailAdapter = new ZimbraMailAdapter(mbox, handler);
/*     */     try
/*     */     {
/* 402 */       SIEVE_FACTORY.evaluate(mailAdapter, node);
/*     */     } catch (SieveException e) {
/* 404 */       throw ServiceException.FAILURE("Unable to evaluate script", e);
/*     */     }
/*     */     
/* 407 */     return handler.filtered();
/*     */   }
/*     */   
/*     */   public static Node parse(String script)
/*     */     throws ParseException
/*     */   {
/*     */     ByteArrayInputStream sin;
/*     */     try
/*     */     {
/* 416 */       sin = new ByteArrayInputStream(script.getBytes("UTF-8"));
/*     */     } catch (UnsupportedEncodingException e) {
/* 418 */       throw new ParseException(e.getMessage());
/*     */     }
/* 420 */     return SIEVE_FACTORY.parse(sin);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public static void folderRenamed(Account account, String originalPath, String newPath)
/*     */     throws ServiceException
/*     */   {
/* 429 */     folderRenamed(account, originalPath, newPath, "zimbraMailSieveScript", FILTER_RULES_CACHE_KEY);
/* 430 */     folderRenamed(account, originalPath, newPath, "zimbraMailOutgoingSieveScript", OUTGOING_FILTER_RULES_CACHE_KEY);
/*     */   }
/*     */   
/*     */   private static void folderRenamed(Account account, String originalPath, String newPath, String sieveScriptAttrName, String rulesCacheKey) throws ServiceException
/*     */   {
/* 435 */     String script = getRules(account, sieveScriptAttrName);
/* 436 */     if (script != null) {
/*     */       Node node;
/*     */       try {
/* 439 */         node = parse(script);
/*     */       } catch (ParseException e) {
/* 441 */         ZimbraLog.filter.warn("Unable to update filter rules with new folder path '%s'.", e);
/* 442 */         return;
/*     */       }
/* 444 */       FolderRenamer renamer = new FolderRenamer(originalPath, newPath);
/* 445 */       renamer.accept(node);
/* 446 */       if (renamer.renamed())
/*     */       {
/*     */ 
/*     */ 
/*     */ 
/* 451 */         List<String> ruleNames = getRuleNames(script);
/* 452 */         SieveToSoap sieveToSoap = new SieveToSoap(ruleNames);
/* 453 */         sieveToSoap.accept(node);
/* 454 */         SoapToSieve soapToSieve = new SoapToSieve(sieveToSoap.toFilterRules());
/* 455 */         String newScript = soapToSieve.getSieveScript();
/* 456 */         setRules(account, newScript, sieveScriptAttrName, rulesCacheKey);
/* 457 */         ZimbraLog.filter.info("Updated %s due to folder move or rename from %s to %s.", new Object[] { sieveScriptAttrName, originalPath, newPath });
/*     */         
/* 459 */         ZimbraLog.filter.debug("Old rules:\n%s, new rules:\n%s", new Object[] { script, newScript });
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public static void folderDeleted(Account account, String originalPath)
/*     */     throws ServiceException
/*     */   {
/* 469 */     folderDeleted(account, originalPath, "zimbraMailSieveScript", FILTER_RULES_CACHE_KEY);
/* 470 */     folderDeleted(account, originalPath, "zimbraMailOutgoingSieveScript", OUTGOING_FILTER_RULES_CACHE_KEY);
/*     */   }
/*     */   
/*     */   private static void folderDeleted(Account account, String originalPath, String sieveScriptAttrName, String rulesCacheKey) throws ServiceException
/*     */   {
/* 475 */     String script = getRules(account, sieveScriptAttrName);
/* 476 */     if (script != null) {
/*     */       Node node;
/*     */       try {
/* 479 */         node = parse(script);
/*     */       } catch (ParseException e) {
/* 481 */         ZimbraLog.filter.warn("Unable to update filter rules after folder '%s' was deleted.", originalPath, e);
/* 482 */         return;
/*     */       }
/* 484 */       FolderDeleted deleted = new FolderDeleted(originalPath);
/*     */       
/* 486 */       deleted.accept(node);
/* 487 */       if (deleted.modified())
/*     */       {
/*     */ 
/*     */ 
/*     */ 
/* 492 */         List<String> ruleNames = getRuleNames(script);
/* 493 */         SieveToSoap sieveToSoap = new SieveToSoap(ruleNames);
/* 494 */         sieveToSoap.accept(node);
/* 495 */         SoapToSieve soapToSieve = new SoapToSieve(sieveToSoap.toFilterRules());
/* 496 */         String newScript = soapToSieve.getSieveScript();
/* 497 */         setRules(account, newScript, sieveScriptAttrName, rulesCacheKey);
/* 498 */         ZimbraLog.filter.info("Updated %s filter rules after folder %s was deleted.", new Object[] { sieveScriptAttrName, originalPath });
/* 499 */         ZimbraLog.filter.debug("Old rules:\n%s, new rules:\n%s", new Object[] { script, newScript });
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public static void tagRenamed(Account account, String originalName, String newName)
/*     */     throws ServiceException
/*     */   {
/* 510 */     tagRenamed(account, originalName, newName, "zimbraMailSieveScript", FILTER_RULES_CACHE_KEY);
/* 511 */     tagRenamed(account, originalName, newName, "zimbraMailOutgoingSieveScript", OUTGOING_FILTER_RULES_CACHE_KEY);
/*     */   }
/*     */   
/*     */   private static void tagRenamed(Account account, String originalName, String newName, String sieveScriptAttrName, String rulesCacheKey) throws ServiceException
/*     */   {
/* 516 */     String rules = getRules(account, sieveScriptAttrName);
/* 517 */     if (rules != null) {
/* 518 */       String newRules = rules.replace("tag \"" + originalName + "\"", "tag \"" + newName + "\"");
/* 519 */       if (!newRules.equals(rules)) {
/* 520 */         setRules(account, newRules, sieveScriptAttrName, rulesCacheKey);
/* 521 */         ZimbraLog.filter.info("Updated %s due to tag rename from %s to %s.", new Object[] { sieveScriptAttrName, originalName, newName });
/*     */         
/* 523 */         ZimbraLog.filter.debug("Old rules:\n%s, new rules:\n%s", new Object[] { rules, newRules });
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public static void tagDeleted(Account account, String tagName) throws ServiceException
/*     */   {
/* 530 */     tagDeleted(account, tagName, "zimbraMailSieveScript", FILTER_RULES_CACHE_KEY);
/* 531 */     tagDeleted(account, tagName, "zimbraMailOutgoingSieveScript", OUTGOING_FILTER_RULES_CACHE_KEY);
/*     */   }
/*     */   
/*     */   private static void tagDeleted(Account account, String tagName, String sieveScriptAttrName, String rulesCacheKey) throws ServiceException
/*     */   {
/* 536 */     String script = getRules(account, sieveScriptAttrName);
/* 537 */     if (script != null) {
/*     */       Node node;
/*     */       try {
/* 540 */         node = parse(script);
/*     */       } catch (ParseException e) {
/* 542 */         ZimbraLog.filter.warn("Unable to update %s after tag '%s' was deleted.", sieveScriptAttrName, tagName, e);
/* 543 */         return;
/*     */       }
/* 545 */       TagDeleted deleted = new TagDeleted(tagName);
/*     */       
/* 547 */       deleted.accept(node);
/* 548 */       if (deleted.modified())
/*     */       {
/*     */ 
/*     */ 
/*     */ 
/* 553 */         List<String> ruleNames = getRuleNames(script);
/* 554 */         SieveToSoap sieveToSoap = new SieveToSoap(ruleNames);
/* 555 */         sieveToSoap.accept(node);
/* 556 */         SoapToSieve soapToSieve = new SoapToSieve(sieveToSoap.toFilterRules());
/* 557 */         String newScript = soapToSieve.getSieveScript();
/* 558 */         setRules(account, newScript, sieveScriptAttrName, rulesCacheKey);
/* 559 */         ZimbraLog.filter.info("Updated %s after tag %s was deleted.", new Object[] { sieveScriptAttrName, tagName });
/* 560 */         ZimbraLog.filter.debug("Old rules:\n%s, new rules:\n%s", new Object[] { script, newScript });
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/filter/RuleManager.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */